package com.satan.juc.demo02;

import java.util.concurrent.FutureTask;

/**
 * @Author: Demon
 * @Date: 2024/3/28 16:49
 * @Description:
 **/
public class CreateThreadDemo {
    public static void main(String[] args) {
        //1.继承Thread
        Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();
                System.out.println("继承Thread");
            }
        };
        thread.start();
        //2.实现runable接口
        Thread thread1 = new Thread(()->{
            System.out.println("实现runable接口");
        });
        thread1.start();
        //3.实现callable接口
        FutureTask futureTask = new FutureTask<>(()->{
            return "通过实现Callable接口";
        });
        Thread thread2 = new Thread(futureTask);
        thread2.start();
        try {
            System.out.println(futureTask.get());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
